package com.hotel.tv.application.callback;

import com.autumn.runtime.session.AutumnSession;
import com.autumn.zero.authorization.application.services.callback.AuthCallback;
import com.autumn.zero.authorization.utils.AuthUtils;
import com.hotel.tv.constants.SysResourcesTypeConstants;
import com.hotel.tv.runtime.session.HotelAdminSession;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

/**
 * <p>
 * </p>
 *
 * @description TODO
 * @author: 老码农
 * @create: 2020-04-10 16:10
 **/
@Component
@Primary
public class HotelAuthCallback implements AuthCallback {

    @Override
    public int moduleResourcesType(AutumnSession session) {
        if (session instanceof HotelAdminSession) {
            HotelAdminSession adminSession = (HotelAdminSession) session;
            if (adminSession.isAdministratorUser()) {
                return SysResourcesTypeConstants.ADMIN_RESOURCES;
            }
            if (adminSession.isHotelUser()) {
                return SysResourcesTypeConstants.HOTEL_RESOURCES;
            }
        }
        return 0;
    }

    @Override
    public String createRandomUserName() {
        return AuthUtils.randomUserName();
    }
}
